/**
 * @description 获取 Mock 咨询列表数据
 */
const getMockConsultationList = () => {
    return [
      {
        id: 'C001',
        patientName: '张伟',
        gender: '男',
        age: 35,
        chiefComplaint: '牙龈肿痛，感觉左下后牙有松动。',
        status: '待回复', // 待回复/处理中/已结束/待处理
        latestMessage: '医生您好，这个周末可以开始治疗吗？',
        latestTime: '2025-11-26 18:30',
        unreadCount: 1,
        priority: 1 // 1:普通, 2:紧急
      },
      {
        id: 'C002',
        patientName: '李小美',
        gender: '女',
        age: 28,
        chiefComplaint: '智齿区域隐痛，刷牙出血。',
        status: '处理中',
        latestMessage: '已收到您的诊断，正在预约拔牙时间。',
        latestTime: '2025-11-25 10:15',
        unreadCount: 0,
        priority: 1
      },
      {
        id: 'C003',
        patientName: '王强',
        gender: '男',
        age: 45,
        chiefComplaint: '根管治疗后牙齿敏感，想咨询复诊事宜。',
        status: '已结束',
        latestMessage: '感谢医生，复诊时间已确定。',
        latestTime: '2025-11-24 09:00',
        unreadCount: 0,
        priority: 2
      },
      {
        id: 'C004',
        patientName: '赵丽',
        gender: '女',
        age: 22,
        chiefComplaint: '牙齿美白咨询，是否有副作用。',
        status: '待回复',
        latestMessage: '请医生尽快给我一个建议，谢谢！',
        latestTime: '2025-11-26 20:20',
        unreadCount: 3,
        priority: 2
      }
    ];
  };
  
  Page({
    data: {
      consultationList: [],
      // 筛选状态
      statusTabs: ['全部', '待回复', '处理中', '已结束'],
      currentStatus: '待回复', // 默认选中待回复
      mockList: getMockConsultationList() // 存储所有 mock 数据
    },
  
    onLoad: function () {
      this.filterList(this.data.currentStatus);
    },
    
    /**
     * 切换筛选标签
     */
    handleTabChange: function (e) {
      const status = e.currentTarget.dataset.status;
      this.setData({
        currentStatus: status
      });
      this.filterList(status);
    },
  
    /**
     * 根据状态筛选列表
     */
    filterList: function (status) {
      let filteredList = this.data.mockList;
      if (status !== '全部') {
        filteredList = this.data.mockList.filter(item => item.status === status);
      }
      this.setData({
        consultationList: filteredList
      });
    },
  
    /**
     * 跳转到详细咨询聊天界面
     */
    goToDetail: function (e) {
      const { id } = e.currentTarget.dataset;
      // 传递 ID 到详情页，详情页根据 ID 加载数据
      wx.navigateTo({
        url: `/pages/doctor/consultationDetail/consultationDetail?id=${id}`
      });
      // 模拟点击后未读消息清零
      const index = e.currentTarget.dataset.index;
      const key = `consultationList[${index}].unreadCount`;
      this.setData({
        [key]: 0
      });
    }
  });